package read;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class Read {

	public static void main(String[] args) throws Exception {
		File dir = new File("");
		System.out.println(dir.getAbsolutePath());
		System.out.println(dir.getCanonicalPath());
		String path  = dir.getAbsolutePath();
//		POIExcelUtil.read_Excel(path+"\\src\\read\\template.xlsx", 1);
		testB(path+"\\src\\read\\template2.xlsx",path+"\\src\\read\\template3.xlsx",path+"\\src\\read\\template4.xlsx");
	}
	
	static void  testA(String fromfile,String tofile) throws IOException{
		FileInputStream fis = new FileInputStream(fromfile);
		// 去读取Excel
		XSSFWorkbook wb = new XSSFWorkbook(fis);
		// 循环Excel的每一个sheet页
		int numberOfSheets = wb.getNumberOfSheets();
		
		XSSFSheet sheet = wb.getSheetAt(0);
		
		XSSFSheet tsheet = wb.createSheet("wwe");
		tsheet=sheet;
		
		FileOutputStream outputStream = new FileOutputStream(tofile);
		wb.write(outputStream);
		outputStream.flush();
		outputStream.close();
		
		fis.close();
		
	}
	
	static void  testB(String fromfile,String tofile,String toofile) throws Exception{
		FileInputStream fis = new FileInputStream(fromfile);
		// 去读取Excel
		XSSFWorkbook wb = new XSSFWorkbook(fis);
		
		XSSFSheet sheet = wb.getSheetAt(0);
		
		
		FileInputStream fis2 = new FileInputStream(tofile);
		// 去读取Excel
		XSSFWorkbook wb2 = new XSSFWorkbook(fis2);
		
		XSSFSheet tosheet =wb2.createSheet("wwe");
		
		
		FileOutputStream outputStream = new FileOutputStream(toofile);
		wb2.write(outputStream);
		outputStream.flush();
		outputStream.close();
		fis.close();
		fis2.close();
		
		PoiCopySheetUtil.copySheet(tosheet, sheet, wb2, wb, false);

		fis.close();
		
	}

}
